var channeldayCheckedItems;
var data_data;
function getchanneldayData() {
    
    
    
	var startDate = $("#channeldayStartDate").val();
	var endDate = $("#channeldayEndDate").val();
    
    
        
    var osID = document.getElementById("channeldayOS").options[document.getElementById("channeldayOS").selectedIndex].value;
    var typeID = document.getElementById("channeldayType").options[document.getElementById("channeldayType").selectedIndex].value;
    
   

	$(".channeldayChart").html("");
	if (startDate != "" && endDate != "")
	{
		var start = new Date();
		var end = new Date();

		//统计项
		var items = document.getElementsByName("channeldayCheckbox");
		channeldayCheckedItems = new Array();
		for(var i=0;i<items.length;i++) {
			if (items[i].checked)
			{
				channeldayCheckedItems.push(items[i].value);
			}
		}

		if(channeldayCheckedItems.length > 0) {


			jQuery('#body-wrapper').showLoading();
			start.setFullYear(startDate.substring(0,4), startDate.substring(5,7)-1, startDate.substring(8,10));
			end.setFullYear(endDate.substring(0,4), endDate.substring(5,7)-1 ,endDate.substring(8,10));

			days = parseInt((end - start)/1000/60/60/24)+1;

			var APIurl = "/client/channelday?staDate="+startDate+"&pd="+days;
	        
            
            if (osID != ""){
				APIurl += "&os="+osID;
            }
			if (typeID != ""){
				APIurl += "&dt="+typeID;
            }
            

			
			$.ajax({
				type: "GET",
				url: APIurl,
				dataType : "json",
				jsonnp: "callback",
				success:function(data,textStatus){ loadchanneldayData(data)}
			});
            
            
            $.ajax({
  url: APIurl,
  type: "POST",
  data: "username="+login_username,
success: function(msg){
   //alert('ok');
}
});
            
		}
		else {
			alert("请选择至少一个统计项");
		}

	}
	else {
		alert("请选择时间区域");
	}
}


var channeldayTabArr, channeldayDetailArr, channeldaySumArr, channeldayDateArr, MainSubTitle;
function loadchanneldayData(data) {
    
    var osID = document.getElementById("channeldayOS").options[document.getElementById("channeldayOS").selectedIndex].value;
    var typeID = document.getElementById("channeldayType").options[document.getElementById("channeldayType").selectedIndex].value;
    
    data_data = data;
	var tab = "";
	var startDate = $("#channeldayStartDate").val();
	var endDate = $("#channeldayEndDate").val();
	MainSubTitle = startDate.replace(/\//g, "-") + " 至 " + endDate.replace(/\//g, "-");
	jQuery('#body-wrapper').hideLoading();	


	channeldayTabArr = new Array();
	channeldayDetailArr = new Array();
	channeldaySumArr = new Array();
	channeldayDateArr = new Array();
    
    
    if(data['zongji'] != "0"){

			//显示选择Tab
			
            if(osID==""){

            genTabschannelday("channelday", "channeldayOS", channeldayTabArr, channeldayDetailArr, channeldaySumArr, channeldayCheckedItems,0);
        }else if(typeID == ""){

            genTabschannelday("channelday", "channeldayType", channeldayTabArr, channeldayDetailArr, channeldaySumArr, channeldayCheckedItems,0);
        }else{ genTabschannelday("channelday","", channeldayTabArr, channeldayDetailArr, channeldaySumArr, channeldayCheckedItems,0);  }
			
            
            //读取数据
            
        if ($("#channeldayPieTab").hasClass("selbitem")){
            
			changeChartType('channelday', 'Pie');
        }
        
        if ($("#channeldayTableTab").hasClass("selbitem")){
            
			changeChartType('channelday','Table');
        }
        
        if (!$("#channeldayTableTab").hasClass("selbitem") && !$("#channeldayPieTab").hasClass("selbitem")){
            
			changeChartType('channelday','Table');
        }
        
        
        
        //生成表格
        genTop10Tablechannelday("channeldayTable", valueFullNameArr(channeldayCheckedItems), channeldayTabArr, data['All']['table'], channeldayCheckedItems);
        
        //生成饼图
        genPieChartchannelday("channeldayPie",data['All']['bingtu'],"播放量(VV) Top10频道");
        
    }
    else{
        
    alert("选择的时间区间内无数据");
    
    }
	
}

function changechanneldayTab(tabName,optionName) {
	
        
    
        //生成表格
        genTop10Tablechannelday("channeldayTable", valueFullNameArr(channeldayCheckedItems), channeldayTabArr, data_data[tabName]['table'], channeldayCheckedItems);
        
        //生成饼图
        genPieChartchannelday("channeldayPie",data_data[tabName]['bingtu'],"播放量(VV) Top10频道");
    
    
    
	$(".bitem").removeClass("selbitem");
	$("#channeldayTab"+tabName).addClass("selbitem");	
    
    
    
	
}



